*********************************************************
* READ-ME: THE ECONOMIC CONSEQUENCES OF SLEEP DEPRIVATION
*********************************************************
***** Overview:

This is the replication package for �The Economic Consequences of Increasing Sleep Among the Urban Poor,� by Pedro Bessone, Gautam Rao, Frank Schilbach, Heather Schofield, and Mattie Toma. 

This folder contains all the data and code necessary for replicating the tables and figures in the paper, as well as English translations of the survey instruments used in data collection. The files are largely in Stata format, but also include data in .csv and .xslsx files. The replication time will depend on whether the randomization inference iterations are run for the adjusted p-values: replicating without takes about 30 minutes; replicating with can take much longer.  

***** Top-folder structure:
-Datasets
-master.do
-Output
     -Appendix
         -figures
         -tables
     -Main_paper
         -figures
         -tables
-Readme.txt
-Scripts
     -anderson_index_program.do     -anderson_index_program_iv.do     -adjust_pval_step_down_fun.R
     -Appendix
     -Main_paper
-Surveys

***** Replication instructions:
1. Open master.do and follow the instructions below (also in master.do)
2. Set the path to the data folder in the lines marked "SET DIRECTORY HERE" (Lines 19 and 44 or 54)
3  Set the two globals that determine how the program runs. The first, "RI", sets whether the program runs the randomization inference iterations. If it is set to "1" it will. Otherwise, it will not. The second, "reps", determines the number of iterations in the RI files. 10,000 are required to perfectly replicate the adjusted p-values in the paper. 
4. Run master.do

Replication notes:
1. The user-written commands that are necessary to replicate are listed in section 2 of the master do-file. After the first time you run the file, you might want to comment these out in order to save run time.
2. The package currently uses a stata package, RSource, in order to run the r scripts necessary to replicate within Stata. If you would not like to run the R scripts in stata, set global RI to 0 and comment out the rsource commands at the bottom of the master do-file.

***** Dataset information, availability, and provenance:
This package contains data from an RCT conducted in Chennai, India, between 2017 and 2019. 

The data comes from 7 sources:
1. A baseline survey of participants
2. Actigraph device sleep measurements throughout the 28-day study period
3. Data on productivity, output, and earnings from daily data-entry tasks
4. Smaller, daily surveys that recorded variables like self-reported sleep, measures of well-being, etc.
5. Daily lab experiments that measured savings behavior and cognition
6. A survey of experts that gathered prior beliefs on treatment effects
7. A larger-scale sleep survey of a broader sample that was more representative of Chennai. This survey in itself contained three segments: i) A Census and Baseline survey, in which
individuals were asked a set of questions about their personal and self-reported sleep characteristics; (ii) an Actigraph study, where participants wore an actigraph for three nights; and (iii) and Endline survey, where participants who undertook the Actigraph study were asked to self-report their sleep patterns over the previous four days.

The data from the above sources is publicly available at the QJE dataverse (https://dataverse.harvard.edu/dataverse/qje) under license CC0. The available data is cleaned analysis data; variables are labelled, and where applicable, have had generations marked (many variables are standardized, etc.).

For more information on the data sources for this replication package, see section 3 of the associated paper and sections C-F of its online appendix.


***** Dataset list:
The following datasets are included base-datasets (i.e., not generated by running the replication code):
	actigraph_night_cleaned (.dta)
	analysis_base (.dta)
	attendance_dataset (.dta)
	balance_dataset (.dta)
	baseline_cleaned (.dta)
	cognitive_tasks_dataset (.dta)
	epoch_dataset (.dta)
	firststage_dataset (.dta)
	health_dataset (.dta)
	heterogeneity_dataset (.dta)
	pb_dataset (.dta)
	pop_study_dataset (.dta)
	pvt_dataset (.dta)
	riskandsocial_dataset (.dta)
	salience_dataset (.dta)
	savings_dataset (.dta)
	sleep_examples_dataset (.dta)
	sleepaid_beforepid5191 (.xlsx)
	sleepaid_installation_cleaned (.dta)
	sleepfactorsaid_dataset (.dta)
	summary_coefficients (.csv)
	survey_of_experts (.dta)
	typing_by_clock (.dta)
	typing_dataset (.dta)
	typing_merged_pid_day (.dta)

The following datasets are included generated-datasets (i.e., replaced each time the replication code is run):	
	anderson_indices (.dta)
	mht_ri_pvals_table_pool (.dta)	mht_ri_pvals_table_int_pool (.dta)	mht_ri_pvals_table_disag (.dta)	main_index_dataset (.dta)
	pvals_unadjusted (.dta)	pvals_unadjusted (.csv)	pvals_unadjusted_table_interaction (.dta)	pvals_unadjusted_table_interaction (.csv)	pvals_unadjusted_table_int_pooled (.dta)	pvals_unadjusted_table_int_pooled (.csv)	pvals_unadjusted_table_instrumental (.dta)	pvals_unadjusted_table_instrumental (.csv)	pvals_unadjusted_table_break_work2 (.dta)	pvals_unadjusted_table_break_work2 (.csv)	pvals_unadjusted_table_break_work1 (.dta)	pvals_unadjusted_table_break_work1 (.csv)	pvals_unadjusted_table_break_work (.dta)	pvals_unadjusted_table_break_work (.csv)	pval_adj_table_work_break (.csv)	pval_adj_table_pool (.csv)	pval_adj_table_int_pooled (.csv)	pval_adj_table_disag (.csv)	pval_adj_all_instrumental (.xlsx)

			
***** Computational requirements:
All programs were written in Stata and R. The following non-base packages are required:

Stata:           R:
-reghdfe		-pacman
-distinct	-ggplot2
-coefplot	-ggrepel
-mdesc		-multtest
-ivreghdfe	-rio
-qqvalue		-tidyverse
-rsource	
	
The code was last run in Stata 16 on a 1.2 GHz Dual-Core Intel Core m3 computer with MacOS version 11.2.3. Replicating without the randomization inference iterations took approximately 30 minutes. A run to fully replicate the paper requires 30,000 total iterations (10,000*3). The above system could perform one iteration in ~15 seconds.

***** Description of programs/code (+list of code and output):
With the exception of the randomization inference files, each do-file in the �scripts� folder reproduces exactly one table or figure from the paper, outputting the results into a similarly named file in the �Output� folders. The scripts with the �A� prefix produce appendix tables/figures, and the results output to the �Output/Appendix� folder; the do-files without the �A� prefix reproduce the tables from the main paper, and output results to the �Output/Main_paper� folder. 

Master.do runs set-up, sets globals, and calls all scripts.

Tables/Figures	Scripts (Scripts/)		Outputs (Output/)

Figure 1		/Main_paper/Figure_1.do		/Main_paper/Figures/Figure1_good_sleep
						/Main_paper/Figures/Figure1_typical_sleep
Figure 2		/Main_paper/Figure_2.do		/Main_paper/Figures/Hist_act_inbed_baseline
						/Main_paper/Figures/Hist_epoch_sleepeff_baseline
						/Main_paper/Figures/Hist_self_report_eff_baseline
						/Main_paper/Figures/Hist_self_report_inbed_baseline
						/Main_paper/Figures/Hist_self_report_sleep_baseline
						/Main_paper/Figures/Hist_Sleep_Night_baseline
Figure 4		/Main_paper/Figure_4.do		/Main_paper/Figures/Figure4survey_experts
Figure 5		/Main_paper/Figure_5.do		/Main_paper/Figures/Mean_Daily_act_inbed_only_one_cell
						/Main_paper/Figures/Mean_Daily_epoch_sleepefficiency_only_one_cell
						/Main_paper/Figures/Mean_Daily_nap_time_mins_only_one_cell
						/Main_paper/Figures/Mean_Daily_Sleep_Night_only_one_cell
Figure 6		/Main_paper/Figure_6.R		/Main_paper/Figures/Figure6_summary_both
Table 1		/Main_paper/Table_1.do		/Main_paper/Tables/Table1_sleep_statistics.tex
Table 2		/Main_paper/Table_2.do		/Main_paper/Tables/Table2_treatment_effects_on_sleep_cell.tex
Table 3		/Main_paper/Table_3.do		/Main_paper/Tables/Table3A_table_main_int_separated_cell1_nomht.tex
						/Main_paper/Tables/Table3B_table_main_int_separated_cell2_nomht.tex
Table 4		/Main_paper/Table_4.do		/Main_paper/Tables/Table4A_table_main_anderson_join1.tex
						/Main_paper/Tables/Table4B_table_main_anderson_join2.tex
		/Main_paper/Table_4_RI.do		/Datasets/mht_ri_pvals_table_pool.dta
		/Main_paper/Table_adjust_pval.R	Datasets/pval_adj_table_pool.csv
Figure A1	/Appendix/Figure_A1.do		/Appendix/Figures/asleep_by_hour_30
						/Appendix/Figures/in_bed_by_hour_30
Figure A2	/Appendix/Figure_A2.R		/Appendix/Figures/Figure_A2_hist_mins_naps.pdf
Figure A4	/Appendix/Figure_A4.do		/Appendix/Figures/ds_sleep_factors_categorized
						/Appendix/Figures/sleep_aid_usage
						/Appendix/Figures/fraction_sleepaids_install
Figure A5	/Appendix/Figure_A5.do		/Appendix/Figures/Mean_Daily_act_inbed_fully_disag
						/Appendix/Figures/Mean_Daily_epoch_sleepefficiency_fully_disag
						/Appendix/Figures/Mean_Daily_nap_time_mins_fully_disag
						/Appendix/Figures/Mean_Daily_Sleep_Night_fully_disag
Figure A6	/Appendix/Figure_A6.do		/Appendix/Figures/earn_by_day
						/Appendix/Figures/prod_by_day
						/Appendix/Figures/typing_time_by_day.png
Figure A7	/Appendix/Figure_A7.do		/Appendix/Figures/frac_present_nap_treat
						/Appendix/Figures/frac_present_night-sleep_treat
Figure A8	/Appendix/Figure_A8.do		/Appendix/Figures/FigureA8_productivity_by_clock_nap
Figure A9	/Appendix/Figure_A9.R		/Appendix/Figures/FigureA9_scatter_sleep_vs_overall_if
Table A1		/Appendix/Table_A1.do		/Appendix/Tables/TableA1a_balance1_six_index.tex
						/Appendix/Tables/TableA1b_balance2_six_index.tex
Table A2		/Appendix/Table_A2.do		/Appendix/Tables/TableA2a_balance1_pooled_index.tex
Table A4		/Appendix/Table_A4.do		/Appendix/Tables/TableA4_survey_experts.tex
Table A5		/Appendix/Table_A5.do		/Appendix/Tables/TableA5_main_firststage_hte.tex
Table A6		/Appendix/Table_A6.do		/Appendix/Tables/TableA6_first_stage_manual_att_bounds.tex
Table A7		/Appendix/Table_A7.do		/Appendix/Tables/TableA7a_main_int_separated_cell1.tex
						/Appendix/Tables/TableA7b_main_int_separated_cell2.tex
		/Appendix/Table_A7_RI		/Datasets/mht_ri_pvals_table_disag.dta
		/Appendix/Table_A7_adjust_pval.R  /Datasets/pval_adj_table_disag.csv
Table A8		/Appendix/Table_A8.do		/Appendix/Tables/TableA8a_main_interaction_cell_part1.tex
						/Appendix/Tables/TableA8b_main_interaction_cell_part2.tex
		/Appendix/Table_A8_RI		/Datasets/mht_ri_pvals_table_int_pool.dta
		/Appendix/Table_A8_adjust_pval.R. /Datasets/pval_adj_table_int_pooled.csv
Table A9		/Appendix/Table_A9.do		/Appendix/Tables/TableA9a_main_breakdown_work_break_mht_part1.tex
						/Appendix/Tables/TableA9b_main_breakdown_work_break_mht_part2.tex
		/Appendix/Table_A9_adjust_pval.R  /Datasets/pval_adj_table_work_break.csv
Table A10	/Appendix/Table_A10.do		/Appendix/Tables/TableA10_decomposition_time_allocation.tex
Table A11	/Appendix/Table_A11.do		/Appendix/Tables/TableA11_wellbeing.tex
Table A12	/Appendix/Table_A12.do		/Appendix/Tables/TableA12_cog_tasks.tex
Table A13 	/Appendix/Table_A13.do		/Appendix/Tables/TableA13_salience.tex
Table A14	/Appendix/Table_A14.do		/Appendix/Tables/TableA14a_time_preferences_part1_new.tex
						/Appendix/Tables/TableA14b_time_preferences_part2_new.tex
Table A15	/Appendix/Table_A15.do		/Appendix/Tables/TableA15_risk_social_pref.tex
Table A16	/Appendix/Table_A16.do		/Appendix/Tables/TableA16_main_overall_index_hte.tex
Table A17	/Appendix/Table_A17.do		/Appendix/Tables/TableA17a_main_anderson_IV_part1.tex
						/Appendix/Tables/TableA17b_main_anderson_IV_part2.tex
		/Appendix/Table_A17_adjust_pval.R /Datasets/pval_adj_all_instrumental.xlsx
Table A18	/Appendix/Table_A18.R		/Appendix/Tables/TableA18/pval_adj_cog.xlsx
						/Appendix/Tables/TableA18/pval_adj_family.xlsx
						/Appendix/Tables/TableA18/pval_adj_pref.xlsx
						/Appendix/Tables/TableA18/pval_adj_wb.xlsx
						/Appendix/Tables/TableA18/pval_adj_work.xlsx
Table A19	/Appendix/Table_A19.do		/Appendix/Tables/TableA19_pb_correlations.tex
Table A20	/Appendix/Table_A20.do		/Appendix/Tables/TableA20_takeup_stagewise.tex
Table A21	/Appendix/Table_A21.do		/Appendix/Tables/TableA21_demographics.tex
Table A22	/Appendix/Table_A22.do		/Appendix/Tables/TableA22_ss_ns_correlates.tex
						

* List of contents in the paper, but not code-generated (can be provided if requested):

		> Figures: III, A.III

		> Tables: A.III




		

